package com.cloud.transaction.service.Impl;

import com.cloud.mapper.UserMapper;
import com.cloud.transaction.service.TransactionService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import javax.annotation.Resource;

@Service
public class TransactionServiceImpl implements TransactionService {
    @Resource
    private UserMapper userMapper;

    /**
     * 手动回滚事务
     * TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
     */
    @Transactional
    @Override
    public void upd() {
        userMapper.updateData("张三123");
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
    }

    /**
     * aop拦截mapper注册注册事务回调接口
     */
    @Transactional
    @Override
    public void updTestAop() {
        userMapper.updateData("张三123");
    }
}
